home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / QuickDraw / Bitblitz 1.0 / Source / OffscreenUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-09  |  2.7 KB  |  93 lines  |  [TEXT/MPS ]

  1. /*--------------------------------------------------------------------------------------
  2. //
  3. //    File:          OffscreenUtils.c
  4. //
  5. //    Contents:    Procedures for the creation, manipulation, and disposal of offscreen bit structures.
  6. //
  7. //
  8. //    By Georgiann ("George") Delaney
  9. //    © 1989 - 1990, Apple Computer, Inc.
  10. //
  11. //--------------------------------------------------------------------------------------*/
  12.  
  13.  
  14. #pragma segment OffscreenSeg
  15.  
  16. #include "MacHeaders.h"
  17.  
  18.  
  19. /*--------------------------------------------------------------------------------------*/
  20. Boolean  CreateOSBitmap(GrafPtr *theOSBitmap, Rect *bounds)
  21. /*
  22.     CreateOSBitmap returns, in the specified pointer, an offscreen bitmap whose size is
  23.     that which was specified in the bounds parameter.
  24. */
  25. {
  26.     GrafPtr        bitsPort;                    /*  temporary storage for new bitmap    */
  27.     GrafPtr        holdPort;                    /*  storage for current port            */
  28.     Rect        bitsRect;                    /*  local copy of specified boundary    */
  29.     Boolean        theReturn     = false;        /*  temp storage for return value        */
  30.     
  31.     
  32.                     /*  Save off the current port so that it can be restored after OpenPort()  */
  33.     GetPort(&holdPort);                
  34.  
  35.                     /*  Convert the rect so that is is zero-based. */
  36.     bitsRect = *bounds;
  37.     OffsetRect(&bitsRect, -bitsRect.top, -bitsRect.left);
  38.  
  39.                     /*  Allocate memory for the offscreen bitmap's */
  40.     bitsPort  = (GrafPtr) NewPtr(sizeof(GrafPort));
  41.     
  42.     if (MemError() == noErr) {
  43.                     /*  Allocate and initialize the offscreen bitmap's clipRgn, visRgn,  etc... */
  44.         OpenPort(bitsPort);        
  45.         bitsPort->portRect    = bitsRect;
  46.         RectRgn(bitsPort->clipRgn,&bitsRect);
  47.         RectRgn(bitsPort->visRgn, &bitsRect);
  48.         
  49.                     /*  Allocate and initialize the offscreen bitmap    */
  50.         bitsPort->portBits.bounds   = bitsRect;
  51.         bitsPort->portBits.rowBytes = ((bitsRect.right  + 15) >> 4) << 1;
  52.         bitsPort->portBits.baseAddr = NewPtr(bitsPort->portBits.rowBytes * (long)bitsRect.bottom);
  53.  
  54.         if (MemError() == noErr) {
  55.                     /*  Clear the bitmap's original contents  */
  56.             EraseRect(&bitsRect);    
  57.             *theOSBitmap = bitsPort;
  58.             theReturn = true;
  59.             }
  60.         else  {
  61.                     /*  Offscreen bitmap alloaction failed.  Dispose all allocated memory  */
  62.             ClosePort(bitsPort);
  63.             DisposPtr((Ptr)bitsPort->portBits.baseAddr);
  64.             }
  65.             
  66.                     /*  Restore the port to that which was set before OpenPort()  */
  67.         SetPort(holdPort);    
  68.         }
  69.  
  70.     return(theReturn);
  71. }
  72.  
  73.  
  74. /*--------------------------------------------------------------------------------------*/
  75. void  DisposeOSBitmap(GrafPtr theOSBitmap)
  76. /*
  77.     DisposeOSBitmap disposes of an offscreen bitmap created with the above offscreen bitmap
  78.     creation function.
  79. */
  80. {
  81.             /*  Close the offscreen bitmap's port  */
  82.     ClosePort(theOSBitmap);
  83.     
  84.             /*  Dispose the offscreen bitmap  */
  85.     DisposPtr((Ptr)theOSBitmap->portBits.baseAddr);
  86.     
  87.             /*  Dispose the offscreen bitmap's port  */
  88.     DisposPtr((Ptr)theOSBitmap);
  89. }
  90.  
  91.  
  92.  
  93.